package sorting;

public class BubbleSort {
	/** The method for sorting the numbers */
	public static void bubbleSort(int[] list) {
		boolean needNextPass = true;
		
		for (int k = 1; k < list.length; k++) {
			// Array may be sorted and next pass not needed
			needNextPass = false;
			for (int i = 0; i < list.length - k; i++) {
				if (list[i] > list[i + 1]) {
					// swap list[i] with list[i + 1]
					int temp = list[i];
					list[i] = list[i + 1];
					list[i + 1] = temp;
	
					needNextPass = true; // Next pass still needed
				}
			}
		}
	}
}



